package com.bear.hospital.service.login.handle;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author： zmwx
 * @Date： 2025/1/23 17:04
 * @Describe： 策略封装
 */
@Component
public class LoginFactory implements InitializingBean {
    @Resource
    List<LoginStrategy> loginStrategyList;
    private final Map<String,LoginStrategy> handlerMap=new HashMap<>();
    @Override
    public void afterPropertiesSet() throws Exception {
        //塞进Map策略对象
        for (LoginStrategy loginStrategy : loginStrategyList){
            handlerMap.put(loginStrategy.getType(),loginStrategy);
        }
    }
    //提供一个入口获取策略对象
    public LoginStrategy getLoginStrategy(String type){
        return handlerMap.get(type);
    }
}
